package com.wyix.entity;

/**
 * @author wangdx
 * @since 2025/8/1
 */
public class Car {
    // 属性（成员变量）
    private String brand;    // 品牌
    private String model;    // 型号
    private double price;    // 价格
    private String color;    // 颜色
    private int productionYear; // 生产年份

    // 构造方法重载
    public Car() {
    }

    public Car(String brand, String model, double price) {
        this.brand = brand;
        this.model = model;
        this.price = price;
    }

    public Car(String brand, String model, double price, String color, int productionYear) {
        this.brand = brand;
        this.model = model;
        this.price = price;
        this.color = color;
        this.productionYear = productionYear;
    }

    // 成员方法
    public void startEngine() {
        System.out.println(brand + model + "的引擎启动了，发出了沉稳的声音");
    }

    public void drive() {
        System.out.println(brand + model + "正在平稳行驶");
    }

    // 计算折扣价格
    public double calculateDiscountedPrice(double discountRate) {
        if (discountRate < 0 || discountRate > 1) {
            throw new IllegalArgumentException("折扣率必须在0到1之间");
        }
        return price * (1 - discountRate);
    }

    // Getter和Setter方法
    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public int getProductionYear() {
        return productionYear;
    }

    public void setProductionYear(int productionYear) {
        this.productionYear = productionYear;
    }

    // 重写toString方法，方便打印对象信息
    @Override
    public String toString() {
        return "Car{" +
                "品牌='" + brand + '\'' +
                ", 型号='" + model + '\'' +
                ", 价格=" + price +
                ", 颜色='" + color + '\'' +
                ", 生产年份=" + productionYear +
                '}';
    }
}
